package com.awspaas.user.apps.cpq.controller;

import com.actionsoft.bpms.commons.mvc.view.ResponseObject;
import com.actionsoft.bpms.server.UserContext;
import com.actionsoft.bpms.util.DBSql;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.springframework.util.ObjectUtils;

public class CPQ_ChangeStatusWeb {

    public String changeStatus(UserContext userContext, String rowData, String boName, String type) {
        try {
            if (!ObjectUtils.isEmpty(rowData)) {
                JSONArray dataList = JSONObject.parseArray(rowData);
                String bindIds = "";
                for (int i = 0; i < dataList.size(); i++) {
                    JSONObject jsonObject = (JSONObject) dataList.get(i);
                    String bindId = (String) jsonObject.get("_BINDID");
                    if (bindIds.isEmpty()) {
                        bindIds = "'" + bindId + "'";
                    } else {
                        bindIds += ",'" + bindId + "'";
                    }
                }
                String sql = "update " + boName + " set STATUS='" + type + "' where BINDID in(" + bindIds + ")";
                DBSql.update(sql);
            }
            ResponseObject ro = ResponseObject.newOkResponse();
            return ro.toString();
        } catch (Exception e) {
            throw e;
        }

    }

    public String changeDeleteStatus(UserContext userContext, String rowData, String boName, String type) {
        try {
            if (!ObjectUtils.isEmpty(rowData)) {
                JSONArray dataList = JSONObject.parseArray(rowData);
                String bindIds = "";
                for (int i = 0; i < dataList.size(); i++) {
                    JSONObject jsonObject = (JSONObject) dataList.get(i);
                    String bindId = (String) jsonObject.get("_BINDID");
                    if (bindIds.isEmpty()) {
                        bindIds = "'" + bindId + "'";
                    } else {
                        bindIds += ",'" + bindId + "'";
                    }
                }
                String sql = "update " + boName + " set SFSC='" + type + "' where BINDID in(" + bindIds + ")";
                DBSql.update(sql);
            }
            ResponseObject ro = ResponseObject.newOkResponse();
            return ro.toString();
        } catch (Exception e) {
            throw e;
        }

    }

}
